{include file="public/header"/}
{include file="public/left"/}
    <div class="content">
        <div class="crumbs clr">系统管理 <span class="red">> 菜单管理</span>
            {if isset($list['id'])}
                <span class="red">> 编辑</span>
            {else /}
                <span class="red">> 新建</span>
            {/if}
        </div>
        <div class="whiteBox">
          <p class="tittle">新建菜单</p>
          <table class="addTab mb20">
            <tr>
              <td>菜单名称：</td>
              <td><input type="text" name="menu_name" value="{$list.menu_name|default=''}"></td>
            </tr>
             <tr>
              <td>上级菜单：</td>
              <td>
                <select name="menu" id="menu">
                  <option value="0">父级菜单</option>
                    {volist name="tree" id='item'}
                    <option {if isset($list['pid']) &&  $list['pid'] eq $item.id }selected{/if} value="{$item.id}">{$item.html}{$item.menu_name}</option>
                    {/volist}
                </select>
              </td>
            </tr>
            <tr>
              <td>菜单代码：</td>
              <td><input type="text" name="menu_tag" value="{$list.menu_tag|default=''}"></td>
            </tr>
              <tr>
                  <td>菜单地址：</td>
                  <td><input type="text" name="menu_url" value="{$list.menu_url|default=''}"></td>
              </tr>
            <tr>
              <tr>
                  <td>菜单排序：</td>
                  <td><input type="text" name="menu_sort" value="{$list.menu_sort|default=''}"></td>
              </tr>
              <td valign="top">描　　述：</td>
              <td>
                <textarea class="loadArea" id="menu_remark">{$list.menu_remark|default=''}</textarea>
              </td>
            </tr>
            <tr>
              <td></td>
              <td align="right"><span class="greyBtn return">返回</span><span class="redBtn ml15 mr50 save">保存</span></td>
            </tr>
          </table>
        </div>
        
    </div>
  {include file="public/footer"/}
<script type="text/javascript">
    $('.save').on('click',function(){
        var id = "{$list.id|default=''}";
        var menu_name = $('input[name="menu_name"]').val();
        if ($.trim(menu_name)=='') {
            layer.alert('请输入菜单名称');
            return false;
        }
        var menuid = $('#menu option:selected').val();
        var menu_url = $('input[name="menu_url"]').val();
        var menu_tag = $('input[name="menu_tag"]').val();
        if ($.trim(menu_tag)=='') {
            layer.alert('请输入菜单代码');
            return false;
        }
        var menu_sort = $('input[name="menu_sort"]').val();
        var menu_remark = $('#menu_remark').val();
        $.post("{:url('admin/menu/editAjax')}", {
            id : id,
            menu_name : menu_name,
            menuid : menuid,
            menu_url : menu_url,
            menu_tag : menu_tag,
            menu_sort : menu_sort,
            menu_remark:menu_remark,
        }, function(data){
            if(data.code==1){
                layer.alert(data.msg, function(index){
                    location.href = "{:url('admin/menu/index')}";
                });
            }else if(data.code==2){
                layer.alert(data.msg);
                return false;
            }else if(data.code==3){
                layer.alert(data.msg, function(index){
                    location.href = "{:url('admin/menu/index')}";
                });
            }else{
                layer.alert(data.msg);
                return false;
            }
        }, 'json');
    });
</script>
</body>
</html>
    